package leetcode.sword;

import java.util.Stack;

public class MinStack {

    Stack<Integer> stack, orderStack;

    /** initialize your data structure here. */
    public static void main(String[] args) {
        MinStack ms = new MinStack();
        System.out.println(ms.stack.pop().equals(ms.orderStack.peek()));
//        MinStack obj = new MinStack();
//        obj.push(512);
//        obj.push(-1024);
//        obj.push(-1024);
//        obj.push(512);
//        obj.pop();
//        System.out.println(obj.min());
//        obj.pop();
//        System.out.println(obj.min());
//        obj.pop();
//        System.out.println(obj.min());
    }


    public MinStack() {
        stack = new Stack<>();
        orderStack = new Stack<>();
    }

    public void push(int x) {
        if(stack.isEmpty()||x<=orderStack.peek()) orderStack.push(x);
        stack.push(x);
    }

    public void pop() {
        boolean s = orderStack.peek().equals(stack.pop());
        if(!orderStack.isEmpty()&&s) orderStack.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int min() {
        return orderStack.peek();
    }
}